<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
<%@ include file="../include/top.jsp"%>
<%@ include file="../include/errorArea.jsp" %>
<link rel="stylesheet" href="${baseURL}/css/zTreeStyle/zTreeStyle.css" type="text/css" />
<script language="javascript" type="text/javascript" src="${baseURL}/js/jquery.ztree.all-3.5.min.js">
</script>
<script type="text/javascript">
	var setting = {
		view: {
			dblClickExpand: false
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClick
		}
	};

	var zNodes = ${treedata}; //后台返回的数据

	function onClick(e,treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj("treeDemo");
		zTree.expandNode(treeNode);

		//叶节点，并且不是第一层节点(第一层节点的pId是null)
		if(!treeNode.isParent && treeNode.pId!=null){
			nodes = zTree.getSelectedNodes();
			$("#selectedNodeName").attr("value", treeNode.name);
			$("#nodeId").attr("value", treeNode.id);
		}
	}

	function showMenu() {
		var cityObj = $("#selectedNodeName");
		var cityOffset = $("#selectedNodeName").offset();
		$("#menuContent").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");

		$("body").bind("mousedown", onBodyDown);
	}
	function hideMenu() {
		$("#menuContent").fadeOut("fast");
		$("body").unbind("mousedown", onBodyDown);
	}
	function onBodyDown(event) {
		if (!(event.target.id == "menuBtn" || event.target.id == "selectedNodeName" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
			hideMenu();
		}
	}

	$(document).ready(function(){
		$.fn.zTree.init($("#treeDemo"), setting, zNodes);
		
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getNodesByParam("id", "${formdata.nodeId}", null);
		if (nodes.length>0) {
			treeObj.selectNode(nodes[0]);
		}

	});
	
	function iFrameHeight1() {   
		var ifm= document.getElementById("scfj");   
		var subWeb = document.frames ? document.frames["scfj"].document : ifm.contentDocument;   
		if(ifm != null && subWeb != null) {
		   ifm.height = subWeb.body.scrollHeight;
		}   
	}
</script>
</head>

<body>
<form id="myForm" name="myForm" method="post" action="${baseURL}/communityServiceMange/saveService">
<input type="hidden" name="id" value="${obj.id}" />
<input type="hidden" id="idNew" name="idNew" value="${idNew}" />
<input name="productPic1" type="hidden" class="myInput" id="productPic0" value="${formdata.productPic1}"/>
<input name="productPic2" type="hidden" class="myInput" id="productPic1" value="${formdata.productPic2}"/>
<input name="productPic3" type="hidden" class="myInput" id="productPic2" value="${formdata.productPic3}" />
<input name="productPic4" type="hidden" class="myInput" id="productPic3" value="${formdata.productPic4}" />
<input name="productPic5" type="hidden" class="myInput" id="productPic4" value="${formdata.productPic5}" />
<table width="100%" border="0" align="center" id="listTable" bgcolor="#FFFFFF" cellpadding="1" cellspacing="0">
	<tr style="display:none">
	  <td colspan="2" height="0" >
	  </td>
    </tr>
    <tr>
		<td align="right">服务ID：</td>
		<td align="left">${obj.id}</td>
	</tr>
    <%-- <tr>
		<td align="right">服务编码：</td>
		<td align="left"><input name="productCode" type="text" id="productCode"
			value="${formdata.productCode}" size="25" maxlength="50" /></td>
	</tr> --%>
	<tr>
		<td align="right"><span class="mustInput">*</span>服务名称 ：</td>
		<td align="left"><input name="productName" type="text" id="productName"
			value="${obj.productName}" size="70" maxlength="50" /></td>
    </tr>
	<tr>
	  <td align="right" width="120"><span class="mustInput">*</span>服务所属分类：</td>
      <td align="left" colspan="3"><input type="hidden" name="nodeId" id="nodeId" value="${obj.nodeId}"/>
			<input name="selectedNodeName" id="selectedNodeName" type="text" readonly value="${obj.selectedNodeName}" size="40" onclick="showMenu()"/>
		<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
			<ul id="treeDemo" class="ztree" style="margin-top:0; width:300px;"></ul>
		</div>	</td>
    </tr>
   <%--  <tr>
		<td align="right">供货商：</td>
		<td align="left">${formdata.supplierId}</td>
	</tr>
	<tr>
		<td align="right">库存数量：</td>
		<td align="left">${formdata.stockNumber}</td>
	</tr>
	<tr>
		<td align="right">销售数量：</td>
		<td align="left">${formdata.sellNumber}</td>
	</tr> --%>
    <%-- <tr> 
      <td align="right">商品介绍： </td>
	  <td>
			 <link rel="stylesheet" href="${baseURL}/kindeditor417/themes/default/default.css" />
			<link rel="stylesheet" href="${baseURL}/kindeditor417/plugins/code/prettify.css" />
			<script charset="utf-8" src="${baseURL}/kindeditor417/kindeditor-all-min.js"></script>
			<script charset="utf-8" src="${baseURL}/kindeditor417/lang/zh_CN.js"></script>
			<script charset="utf-8" src="${baseURL}/kindeditor417/plugins/code/prettify.js"></script>
			<script>
				KindEditor.ready(function(K) {
					editor1 = K.create('textarea[name="productContent"]', {
						cssPath : '${baseURL}/kindeditor417/plugins/code/prettify.css',
						uploadJson : 'kindeditor417/asp/upload_json.asp',
						fileManagerJson : 'kindeditor417/asp/file_manager_json.asp',
						allowFileManager : true,
						afterCreate : function() {
							var self = this;
							K.ctrl(document, 13, function() {
								self.sync();
								K('form[name=myForm]')[0].submit();
							});
							K.ctrl(self.edit.doc, 13, function() {
								self.sync();
								K('form[name=myForm]')[0].submit();
							});
						}
					});
					prettyPrint();
				});
			</script>
	  <textarea name="productContent" cols="60" rows="5" class="myInput" id="productContent">${formdata.productContent}</textarea></td>
    </tr> --%>
    <!-- 
	<tr>
		<td align="right">商品图片1</td>
		<td align="left"><input name="productPic1" type="file" class="myInput" id="productPic1"></td>
	</tr>
	<tr>
		<td align="right">商品图2</td>
		<td align="left"><input name="productPic2" type="file" class="myInput" id="productPic2"></td>
	</tr>
	<tr>
		<td align="right">商品图片3</td>
		<td align="left"><input name="productPic3" type="file" class="myInput" id="productPic3"></td>
	</tr>
	<tr>
		<td align="right">商品图片4</td>
		<td align="left"><input name="productPic4" type="file" class="myInput" id="productPic4"></td>
	</tr>
	<tr>
		<td align="right">商品图片5</td>
		<td align="left"><input name="productPic5" type="file" class="myInput" id="productPic5"></td>
	</tr> -->
	<%-- <tr>
	  <td align="right">供货商的价格：</td>
      <td align="left"><span id="supplierPrice">${formdata.supplierPrice}</span>元（人民币）</td>
	</tr> --%>
	<%-- <tr>
	  <td align="right">加价比例：</td>
      <td align="left">
      	<select name="addPercent" id="addPercent" onChange="countPrice()">
		      <c:forEach var="i" begin="1" end="100">
		      	<option value="${i}">${i}</option>
		      </c:forEach>
	       </select>% 仅用作计算，最终价格以下面的零售价格为准。</td>
	</tr> --%>
	 <tr>
	  <td align="right">服务费用：</td>
      <td align="left">
      	<input name="sellPrice" id="sellPrice" type="text"
			value="${obj.sellPrice}" size="25" maxlength="50"/>元（人民币）
		</td>
	</tr> 
	<tr> 
      <td align="right">说明： </td>
      <td>
							<link rel="stylesheet" href="${baseURL}/kindeditor417/themes/default/default.css" />
							<link rel="stylesheet" href="${baseURL}/kindeditor417/plugins/code/prettify.css" />
							<script charset="utf-8" src="${baseURL}/kindeditor417/kindeditor-all-min.js"></script>
							<script charset="utf-8" src="${baseURL}/kindeditor417/lang/zh_CN.js"></script>
							<script charset="utf-8" src="${baseURL}/kindeditor417/plugins/code/prettify.js"></script>
							<script>
								KindEditor.ready(function(K) {
									editor1 = K.create('textarea[name="productContent"]', {
										cssPath : '${baseURL}/kindeditor417/plugins/code/prettify.css',
										uploadJson : '${baseURL}/kindeditor417/jsp/upload_json.jsp',
										fileManagerJson : '${baseURL}/kindeditor417/jsp/file_manager_json.jsp',
										allowFileManager : true,
										afterCreate : function() {
											var self = this;
											K.ctrl(document, 13, function() {
												self.sync();
												K('form[name=myForm]')[0].submit();
											});
											K.ctrl(self.edit.doc, 13, function() {
												self.sync();
												K('form[name=myForm]')[0].submit();
											});
										}
									});
									prettyPrint();
								});
								
							</script>
					  		<textarea name="productContent" cols="60" rows="5" class="myInput" id="productContent">${formdata.productContent}</textarea>
					  </td>
    </tr>
	<!-- <tr>
	  <td align="right">其它：</td>
      <td align="left">
      	<label><input name="recommendFlag" id="recommendFlag" type="checkbox" class="myInput" value="1"/>推荐商品</label>
      	<label><input name="specialPriceFlag" id="specialPriceFlag" type="checkbox" class="myInput" value="1"/>特价商品</label>
      </td>
	</tr> -->
	<%-- <TR>
		<TD width='150' align='right'>图片上传：</TD>
		<td>
		  	<iframe width=100% height=90 frameborder=0 id="scfj" scrolling=no src="${baseURL}/wjsc/query/${idNew}/update" onload="iFrameHeight1()"></iframe>
		</td>
	</TR> --%>
	<tr>
	  <td colspan="2" align="center">
	  	<input type="button" onclick="infoSubmit()" value="提交" class='button cyan medium'/>
	    &nbsp;&nbsp;
	  </td>
    </tr>
	<tr>
	  <td colspan="4" align="center">&nbsp;</td>
    </tr>
</table>
</form>
<script>
doSelect(myForm.addPercent,"${formdata.addPercent}");
doSelect(myForm.sharePercent,"${formdata.sharePercent}");
$("#recommendFlag").attr("checked", "${formdata.recommendFlag}"=="1");
$("#specialPriceFlag").attr("checked", "${formdata.specialPriceFlag}"=="1");

//计算价格，总是向上取整
function countPrice(){
	var oldPrice = parseFloat($('#supplierPrice').html());
	var finalPercent = 1 + 0.01 * parseInt($('#addPercent').val());
	$('#sellPrice').val(Math.ceil(oldPrice * finalPercent));
	
	countPrice2();
}
//计算实际的加价比例
function countPrice2(){
	var oldPrice = parseFloat($('#supplierPrice').html());
	var finalPrice = parseFloat($('#sellPrice').val());
	var finalPercent = (finalPrice - oldPrice)/oldPrice * 100;
	$('#trueAddPercent').html(finalPercent);
}
function infoSubmit(){
	 var money=document.getElementById("sellPrice").value;
	 if(money==""||isNaN(money)){
			alert("请输入正确的价格。");
			return;
	 }
//var idNew = $("#idNew").val();
	//$.post('${ctx}/wjsc/getFileBmList/'+idNew,function(data, textStatus) {
		//if(textStatus == 'success') {
			//for(var a=0;a<data.length;a++){
				//alert(data[a].wjbm);
				//$("#productPic" + a).val(data[a].wjbm);
			//}
			editor1.sync();
			$("#myForm").submit();
			//document.getElementById("myForm").submit();
		//}
	//},"json"); 
}
</script>
</body>
</html>